//
//  TechingViewController.m
//  MM
//
//  Created by 郑渊文 on 6/3/15.
//  Copyright (c) 2015 王晨辉. All rights reserved.
//

#import "TechingViewController.h"
#import "EndTeachingViewController.h"
@interface TechingViewController ()<UITableViewDataSource,UITableViewDelegate>
{

    UIButton *addBtn;
    UIButton *backBtn;
}
@property(nonatomic,copy)NSMutableArray *timeArray;
@property(nonatomic,copy)NSMutableArray *nameArray;
@property(nonatomic,copy)NSMutableArray *classIdArray;
@property(nonatomic,copy)UITableView *myTable;

@end

@implementation TechingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initSubViews];

    
    _nameArray = [NSMutableArray array];
    _timeArray = [NSMutableArray array];
     _classIdArray = [NSMutableArray array];
    NSDictionary *param4 = @{@"babyId":[BabyManager shareInstance].babyId,@"classStatus":@"1"};
    
    [UserDAL getInteachingParams:param4 withBlock:^(NSDictionary *data, NSError *error) {
        if (data) {
            ////NSLog(@"what%@",data);
            NSArray *array = data[@"dataList"];
            for (NSDictionary *mydic in array) {
                [_nameArray addObject:mydic[@"className"]] ;
                [_timeArray addObject:mydic[@"classStarTime"]] ;
                [_classIdArray addObject:mydic[@"classId"]] ;
            }
            [_myTable reloadData];
            
        }else
        {
            
        }
    }];
//    _nameArray = [NSMutableArray arrayWithObjects:@"《文语文语文》",@"《文语文语文》",@"《文语文语文》",@"《文语文语文》",@"狗屎狗屎狗屎狗屎", nil];
//    _timeArray = [NSMutableArray arrayWithObjects:@"2015-5-12 9:00",@"2015-5-12 9:00",@"2015-5-12 9:00",@"2015-5-12 9:00",@"2015-5-12 9:00", nil];


    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



-(void)initSubViews
{
    //自定义左右按钮
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
     
                      forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(back)
     
     forControlEvents:UIControlEventTouchUpInside];
    
    button.frame = CGRectMake(0, 0, 20, 15);
    
    
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    
    
    self.navigationItem.leftBarButtonItem = menuButton;
    
    self.navigationItem.title = @"上课中";
    [self.navigationController.navigationBar setTranslucent:NO];//设置navigationbar的半透明
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#34bd81" alpha:1]];
    self.view.backgroundColor = [UIColor clearColor];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];

    
      
    
    _myTable = [[UITableView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    _myTable.delegate = self;
    _myTable.dataSource = self;
    [self.view addSubview:_myTable];
    
    
//    UIButton *teachingBtn = [[UIButton alloc]initWithFrame:CGRectMake(50, SCREEN_HEIGHT-150, SCREEN_WIDTH-100, 40)];
//    [teachingBtn setImage:[UIImage imageNamed:@"上课中"] forState:UIControlStateNormal];
//    [teachingBtn addTarget:self action:@selector(teaching) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:teachingBtn];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _nameArray.count;
}


#pragma mark--- tableViewDelegate 区尾的高度

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 1;
    
}
#pragma mark--- tableViewDelegate cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *NOTIFY = @"cell";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:NOTIFY];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NOTIFY];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%@", _timeArray[indexPath.row]];
    cell.textLabel.font = [UIFont systemFontOfSize:13];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    UILabel *typeLable = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2, 10, 100, 30)];
    [cell addSubview:typeLable];
    typeLable.text = _nameArray[indexPath.row];
    typeLable.font = [UIFont systemFontOfSize:12];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
        EndTeachingViewController *setVC = [[EndTeachingViewController alloc]init];
        setVC.classId = _classIdArray[indexPath.row];
        UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:setVC];
        [self  presentViewController:nav animated:YES completion:nil];

}

-(void)addLession
{
    
}


-(void)back
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

-(void)teaching
{
    
}

@end
